package com.young.canal.serializer;

/**
 * @description：
 * @author: yangyahui01
 * @date: 12/11/24 7:05 PM
 */
public enum EventType {

    INSERT(1, "INSERT"),
    UPDATE(2, "UPDATE"),
    DELETE(3, "DELETE"),
    CREATE(4, "CREATE"),
    ALTER(5, "ALTER"),
    ERASE(6, "ERASE"),
    QUERY(7, "QUERY"),
    TRUNCATE(8, "TRUNCATE"),
    RENAME(9, "RENAME"),
    CREATE_INDEX(10, "CREATE_INDEX"),//创建索引
    DELETE_INDEX(11, "DELETE_INDEX");//删除索引
    public int type;
    public String meaning;

    EventType(int type, String meaning) {
        this.type = type;
        this.meaning = meaning;
    }

    public static EventType typeOf(Integer type) {
        if (type == null) {
            return null;
        }
        for (EventType e : values()) {
            if (e.type == type) {
                return e;
            }
        }
        return null;
    }


    public static boolean isDdl(EventType type) {
        return type == EventType.ALTER || type == EventType.CREATE || type == EventType.ERASE
                || type == EventType.RENAME || type == EventType.TRUNCATE || type == EventType.CREATE_INDEX
                || type == EventType.DELETE_INDEX;
    }

    public static boolean isDdl(int value) {
        EventType type = EventType.typeOf(value);
        return isDdl(type);
    }

}

